﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.IO;
using System.Xml;
using BLL;
using DAL;
using Models;
using System.Data;

public partial class cn_member_center_points_for_order_info : System.Web.UI.Page
{
    // Fields

    protected PointsForOrderManager om = new PointsForOrderManager();
    protected PointsForManager pfm = new PointsForManager();


    // Methods
    protected StringBuilder OrderBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["orderNo"] == null)
            {
                return builder;
            }
            DataTable orderInfoByOrderNo = this.om.GetOrderInfoByOrderNo(base.Request.QueryString["orderNo"], (this.Session["user"] as User).Id);
            if (orderInfoByOrderNo.Rows.Count <= 0)
            {
                return builder;
            }
            DataRow row = orderInfoByOrderNo.Rows[0];
            builder.AppendLine("<div>");
            builder.AppendLine("<h6>订单状态 [订单编号：" + row["orderNo"] + "]</h6>");
            switch (Convert.ToInt32(row["orderStatus"]))
            {
                case 0:
                    builder.AppendLine("<p>等待订单处理</p>");
                    break;

                case 1:
                    builder.AppendLine("<p>订单已确认</p>");
                    break;

                case 2:
                    builder.AppendLine("<p>订单已取消</p>");
                    break;

                case 3:
                    builder.AppendLine("<p>订单无效</p>");
                    break;

                case 4:
                    builder.AppendLine("<p>订单已退货</p>");
                    break;
            }
            builder.AppendLine("<p>" + ((Convert.ToInt32(row["payStatus"]) == 0) ? "您尚未完成积分兑换<br /><input id=\"btnOrderPay\" type=\"button\" class=\"submit_btn\" value=\"立即兑换\" />" : "积分兑换完成") + "</p>");
            builder.AppendLine("<input id=\"hdfOrderNo\" type=\"hidden\" value=\"" + row["orderNo"] + "\" />");
            switch (Convert.ToInt32(row["deliveryStatus"]))
            {
                case 0:
                    builder.AppendLine("<p>未发货</p>");
                    break;

                case 1:
                    builder.AppendLine("<p>已发货<br /><input id=\"btnConfirm\" type=\"button\" class=\"submit_btn\" value=\"确认收货\" /></p>");
                    break;

                case 2:
                    builder.AppendLine("<p>已收货</p>");
                    break;
            }
            builder.AppendLine("</div>");
            builder.AppendLine("<table>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<th colspan=\"4\">收货信息</th>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<td><strong>收货人姓名：</strong></td>");
            builder.AppendLine("<td>" + row["consignee"] + "</td>");
            builder.AppendLine("<td><strong>收货地区：</strong></td>");
            builder.AppendLine("<td>" + ((row["region"].ToString().IndexOf(",") != -1) ? (row["region"].ToString().Split(new char[] { ',' }).GetValue(0).ToString() + row["region"].ToString().Split(new char[] { ',' }).GetValue(1).ToString()) : row["region"]) + "</td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<td><strong>详细地址：</strong></td>");
            builder.AppendLine("<td>" + row["address"] + "</td>");
            builder.AppendLine("<td><strong>邮政编码：</strong></td>");
            builder.AppendLine("<td>" + row["zipCode"] + "</td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<td><strong>联系电话：</strong></td>");
            builder.AppendLine("<td>" + row["telephone"] + "</td>");
            builder.AppendLine("<td><strong>手机号码：</strong></td>");
            builder.AppendLine("<td>" + row["mobile"] + "</td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<td colspan=\"1\"><strong>订单附言：</strong></td>");
            builder.AppendLine("<td colspan=\"3\">" + row["postscript"] + "</td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("</table>");
            builder.AppendLine("<table>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<th colspan=\"2\">兑换信息</th>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<td><strong>兑换积分：</strong></td>");
            builder.AppendLine("<td><em>" + row["orderIntegral"] + "</em></td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("</table>");
            builder.AppendLine("<table>");
            builder.AppendLine("<tr>");
            builder.AppendLine("<th>商品图片</th>");
            builder.AppendLine("<th>商品名称</th>");
            builder.AppendLine("<th>兑换积分</th>");
            builder.AppendLine("<th>数量</th>");
            builder.AppendLine("</tr>");
            builder.AppendLine("<tr>");
            DataTable pointsForById = this.pfm.GetPointsForById(Convert.ToInt32(row["goodsEntitys"]));
            builder.AppendLine(string.Concat(new object[] { "<td class=\"firsttd\"><img src=\"", pointsForById.Rows[0]["image"], "\" alt=\"", pointsForById.Rows[0]["name"], "\" /></td>" }));
            builder.AppendLine("<td>" + pointsForById.Rows[0]["name"] + "</td>");
            builder.AppendLine("<td>" + row["orderIntegral"] + "</td>");
            builder.AppendLine("<td>" + row["amount"] + "</td>");
            builder.AppendLine("</tr>");
            builder.AppendLine("</table>");
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["user"] == null)
        {
            base.Response.Redirect("/cn/web_login.html?ru=" + HttpContext.Current.Request.Url.PathAndQuery.Replace("aspx", "html"));
        }
    }

}